// HttpServer.hpp
#pragma once
#include "muduo/server.hpp"
#include <map>
#include <functional>

class HttpServer {
public:
    using HttpRequestCallback = std::function<void(const std::string& method, 
                                                   const std::string& path, 
                                                   const std::map<std::string, std::string>& headers,
                                                   const std::string& body,
                                                   std::string& response)>;
    
    HttpServer(EventLoop* loop, int port);
    void setRequestCallback(const HttpRequestCallback& cb);
    void start();
    
private:
    EventLoop* _loop;
    int _port;
    Acceptor _acceptor;
    HttpRequestCallback _request_callback;
    
    void onConnection(int sockfd);
    static std::map<std::string, std::string> parseHeaders(const std::string& request);
    static std::string parseHttpRequest(const std::string& request, 
                                       std::string& method, 
                                       std::string& path, 
                                       std::string& body);
};